<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="com.gxwgy.wg2404.pojo.UsersPojo" %>
<%@ page import="com.gxwgy.wg2404.pojo.EventsPojo" %>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>管理员面板</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui.css">
    <style>
        body {
            padding: 20px;
            background-color: #f2f2f2;
        }
        .table-container {
            margin: 20px auto;
            background-color: #fff;
            padding: 20px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            border-radius: 8px;
        }
    </style>
</head>
<body>
<div class="layui-container">
    <h1 class="layui-text">管理员面板</h1>

    <!-- 用户管理 -->
    <div class="table-container">
        <h2>用户管理</h2>
        <table class="layui-table">
            <thead>
            <tr>
                <th>用户名</th>
                <th>邮箱</th>
                <th>角色</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <%
                // 获取所有用户
                List<UsersPojo> users = (List<UsersPojo>) request.getAttribute("users");
                if (users != null && !users.isEmpty()) {
                    for (UsersPojo user : users) {
            %>
            <tr>
                <td><%= user.getUsername() %></td>
                <td><%= user.getEmail() %></td>
                <td><%= user.getRole() %></td>
                <td>
                    <a href="<%=request.getContextPath() %>/administrator/editUser?id=<%= user.getId() %>" class="layui-btn layui-btn-sm">编辑</a>
                    <form action="<%= request.getContextPath() %>/administrator/deleteUser" method="post" style="display:inline;">
                        <input type="hidden" name="id" value="<%= user.getId() %>">
                        <button type="submit" class="layui-btn layui-btn-danger layui-btn-sm" onclick="return confirm('确定删除该活动吗？')">删除</button>
                    </form>
                </td>
            </tr>
            <%
                }
            } else {
            %>
            <tr>
                <td colspan="4" class="layui-text-center">暂无用户</td>
            </tr>
            <% } %>
            </tbody>
        </table>
    </div>

    <!-- 活动管理 -->
    <div class="table-container">
        <h2>活动管理</h2>
        <table class="layui-table">
            <thead>
            <tr>
                <th>活动名称</th>
                <th>开始时间</th>
                <th>结束时间</th>
                <th>地点</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <%
                // 获取所有活动
                List<EventsPojo> events = (List<EventsPojo>) request.getAttribute("events");
                if (events != null && !events.isEmpty()) {
                    for (EventsPojo event : events) {
            %>
            <tr>
                <td><%= event.getName() %></td>
                <td><%= event.getStart_time() %></td>
                <td><%= event.getEnd_time() %></td>
                <td><%= event.getLocation() %></td>
                <td><%= event.getStatus() %></td>
                <td>
                    <a href="<%=request.getContextPath() %>/organizer/editEvent?eventId=<%= event.getId() %>" class="layui-btn layui-btn-sm">编辑</a>
                    <form action="<%= request.getContextPath() %>/organizer/deleteEvent" method="post" style="display:inline;">
                        <input type="hidden" name="id" value="<%= event.getId() %>">
                        <button type="submit" class="layui-btn layui-btn-danger layui-btn-sm" onclick="return confirm('确定删除该活动吗？')">删除</button>
                    </form>
                </td>
            </tr>
            <%
                }
            } else {
            %>
            <tr>
                <td colspan="6" class="layui-text-center">暂无活动</td>
            </tr>
            <% } %>
            </tbody>
        </table>
    </div>
</div>

<script src="${pageContext.request.contextPath}/static/layui.js"></script>
<script src="${pageContext.request.contextPath}/static/jquery.min.js"></script>

</body>
</html>
